<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.bundle</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_bundle_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../'>Howl 0.3 Documentation</a></li><li>Spec</li><li>Spec - howl.bundle</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.bundle">howl.bundle</h1>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">_G</span><span class="p">.</span><span class="n">bundles</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">dirs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;&#x000A;</span><span class="n">with_bundle_dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">name</span><span class="p">,</span><span class="w"> </span><span class="n">f</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">with_tmpdir</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;    </span><span class="n">b_dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">name</span><span class="w">&#x000A;    </span><span class="n">b_dir</span><span class="o">\</span><span class="n">mkdir</span><span class="o">!</span><span class="w">&#x000A;    </span><span class="n">f</span><span class="w"> </span><span class="n">b_dir</span><span class="w">&#x000A;&#x000A;</span><span class="n">bundle_init</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">(</span><span class="n">info</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="n">spec</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{})</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">mod</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">author:</span><span class="w"> </span><span class="s1">'bundle_spec'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'spec_bundle'</span><span class="p">,</span><span class="w"> </span><span class="ss">license:</span><span class="w"> </span><span class="s1">'MIT'</span><span class="w">&#x000A;  </span><span class="n">mod</span><span class="p">[</span><span class="n">k</span><span class="p">]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">v</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">k</span><span class="p">,</span><span class="n">v</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="nb">pairs</span><span class="w"> </span><span class="n">info</span><span class="w">&#x000A;  </span><span class="n">ret</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'return { info = {'</span><span class="w">&#x000A;  </span><span class="n">ret</span><span class="w"> </span><span class="o">..=</span><span class="w"> </span><span class="nb">table.concat</span><span class="w"> </span><span class="p">[</span><span class="n">k</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="s1">'="'</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="n">v</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="s1">'"'</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">k</span><span class="p">,</span><span class="n">v</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="nb">pairs</span><span class="w"> </span><span class="n">mod</span><span class="p">],</span><span class="w"> </span><span class="s1">','</span><span class="w">&#x000A;  </span><span class="n">ret</span><span class="w"> </span><span class="o">..=</span><span class="w"> </span><span class="s1">'}, '</span><span class="w">&#x000A;  </span><span class="k">if</span><span class="w"> </span><span class="n">spec</span><span class="p">.</span><span class="n">unload</span><span class="w">&#x000A;    </span><span class="n">ret</span><span class="w"> </span><span class="o">..=</span><span class="w"> </span><span class="s2">"unload = </span><span class="si">#{</span><span class="n">spec</span><span class="p">.</span><span class="n">unload</span><span class="si">}</span><span class="s2"> }"</span><span class="w">&#x000A;  </span><span class="k">else</span><span class="w">&#x000A;    </span><span class="n">ret</span><span class="w"> </span><span class="o">..=</span><span class="w"> </span><span class="s1">'unload = function() end }'</span><span class="w">&#x000A;  </span><span class="n">ret</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id=".unloaded-holds-the-adjusted-names-of-any-unloaded-bundles">.unloaded holds the adjusted names of any unloaded bundles</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_tmpdir</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">dirs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="n">dir</span><span class="p">}</span><span class="w">&#x000A;  </span><span class="k">for</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="p">{</span><span class="s1">'foo-bar'</span><span class="p">,</span><span class="w"> </span><span class="s1">'frob_nic'</span><span class="p">}</span><span class="w">&#x000A;    </span><span class="n">b_dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">name</span><span class="w">&#x000A;    </span><span class="n">b_dir</span><span class="o">\</span><span class="n">mkdir</span><span class="o">!</span><span class="w">&#x000A;    </span><span class="n">b_dir</span><span class="o">\</span><span class="n">join</span><span class="p">(</span><span class="s1">'init.lua'</span><span class="p">).</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bundle_init</span><span class="w"> </span><span class="ss">:name</span><span class="w">&#x000A;&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'foo_bar'</span><span class="p">,</span><span class="w"> </span><span class="s1">'frob_nic'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">unloaded</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_by_name</span><span class="w"> </span><span class="s1">'foo_bar'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'frob_nic'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">unloaded</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">unload</span><span class="w"> </span><span class="s1">'foo_bar'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'foo_bar'</span><span class="p">,</span><span class="w"> </span><span class="s1">'frob_nic'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">unloaded</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="load_from_dir">load_from_dir<span class="arg-list">(dir)</span></h2>&#x000A;&#x000A;<h4 id="raises-an-error-if-dir-is-not-a-directory">raises an error if dir is not a directory</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'directory'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_from_dir</span><span class="w"> </span><span class="nc">File</span><span class="w"> </span><span class="s1">'/not-a-directory'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="raises-an-error-if-the-bundle-init-file-is-missing-or-incomplete">raises an error if the bundle init file is missing or incomplete</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_tmpdir</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'find file'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_from_dir</span><span class="w"> </span><span class="n">dir</span><span class="w">&#x000A;  </span><span class="n">init</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="s1">'init.lua'</span><span class="w">&#x000A;  </span><span class="n">init</span><span class="o">\</span><span class="n">touch</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'Incorrect bundle'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_from_dir</span><span class="w"> </span><span class="n">dir</span><span class="w">&#x000A;  </span><span class="n">init</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'return {}'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'info missing'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_from_dir</span><span class="w"> </span><span class="n">dir</span><span class="w">&#x000A;  </span><span class="n">init</span><span class="p">.</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'return { info = {} }'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'missing info field'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_from_dir</span><span class="w"> </span><span class="n">dir</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="assigns-the-returned-bundle-table-to-bundles-using-the-dir-basename">assigns the returned bundle table to bundles using the dir basename</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">mod</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">author:</span><span class="w"> </span><span class="s1">'bundle_spec'</span><span class="p">,</span><span class="w"> </span><span class="ss">description:</span><span class="w"> </span><span class="s1">'spec_bundle'</span><span class="p">,</span><span class="w"> </span><span class="ss">license:</span><span class="w"> </span><span class="s1">'MIT'</span><span class="w">&#x000A;</span><span class="n">with_bundle_dir</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">dir</span><span class="o">\</span><span class="n">join</span><span class="p">(</span><span class="s1">'init.lua'</span><span class="p">).</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bundle_init</span><span class="w"> </span><span class="n">mod</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_from_dir</span><span class="w"> </span><span class="n">dir</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">bundles</span><span class="p">.</span><span class="n">foo</span><span class="p">.</span><span class="n">info</span><span class="p">,</span><span class="w"> </span><span class="n">mod</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_equal</span><span class="w"> </span><span class="s1">'function'</span><span class="p">,</span><span class="w"> </span><span class="nb">type</span><span class="w"> </span><span class="n">bundles</span><span class="p">.</span><span class="n">foo</span><span class="p">.</span><span class="n">unload</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="massages-the-assigned-module-name-to-fit-with-naming-standards-if-necessary">massages the assigned module name to fit with naming standards if necessary</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_bundle_dir</span><span class="w"> </span><span class="s1">'Test-hello 2'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">dir</span><span class="o">\</span><span class="n">join</span><span class="p">(</span><span class="s1">'init.lua'</span><span class="p">).</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bundle_init</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_from_dir</span><span class="w"> </span><span class="n">dir</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">not_nil</span><span class="w"> </span><span class="n">bundles</span><span class="p">.</span><span class="n">test_hello_2</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="raises-an-error-if-the-bundle-is-already-loaded">raises an error if the bundle is already loaded</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_bundle_dir</span><span class="w"> </span><span class="s1">'two_times'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">dir</span><span class="o">\</span><span class="n">join</span><span class="p">(</span><span class="s1">'init.lua'</span><span class="p">).</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bundle_init</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_from_dir</span><span class="w"> </span><span class="n">dir</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'loaded'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_from_dir</span><span class="w"> </span><span class="n">dir</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="raises-an-error-upon-implicit-global-writes">raises an error upon implicit global writes</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_tmpdir</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">dir</span><span class="o">\</span><span class="n">join</span><span class="p">(</span><span class="s1">'init.lua'</span><span class="p">).</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="sh">[[&#x000A;    file = bundle_file('bundle_aux.lua')&#x000A;    return {&#x000A;      info = {&#x000A;        author = 'spec',&#x000A;        description = 'desc',&#x000A;        license = 'MIT',&#x000A;      },&#x000A;      file = file&#x000A;    }&#x000A;  ]]</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'implicit global'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_from_dir</span><span class="w"> </span><span class="n">dir</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(exposed bundle helpers)</span></h3>&#x000A;&#x000A;<h4 id="bundle_file-provides-access-to-bundle-files">bundle_file provides access to bundle files</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_bundle_dir</span><span class="w"> </span><span class="s1">'test'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">dir</span><span class="o">\</span><span class="n">join</span><span class="p">(</span><span class="s1">'init.lua'</span><span class="p">).</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="sh">[[&#x000A;    local file = bundle_file('bundle_aux.lua')&#x000A;    return {&#x000A;      info = {&#x000A;        author = 'spec',&#x000A;        description = 'desc',&#x000A;        license = 'MIT',&#x000A;      },&#x000A;      unload = function() end,&#x000A;      file = file&#x000A;    }&#x000A;  ]]</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_from_dir</span><span class="w"> </span><span class="n">dir</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">bundles</span><span class="p">.</span><span class="n">test</span><span class="p">.</span><span class="n">file</span><span class="p">,</span><span class="w"> </span><span class="n">dir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="s1">'bundle_aux.lua'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="load_all">load_all<span class="arg-list">()</span></h2>&#x000A;&#x000A;<h4 id="loads-all-found-bundles-in-all-directories-in-bundle.dirs">loads all found bundles in all directories in bundle.dirs</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_tmpdir</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">dirs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="n">dir</span><span class="p">}</span><span class="w">&#x000A;  </span><span class="k">for</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="o">*</span><span class="p">{</span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="s1">'bar'</span><span class="p">}</span><span class="w">&#x000A;    </span><span class="n">b_dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="n">name</span><span class="w">&#x000A;    </span><span class="n">b_dir</span><span class="o">\</span><span class="n">mkdir</span><span class="o">!</span><span class="w">&#x000A;    </span><span class="n">b_dir</span><span class="o">\</span><span class="n">join</span><span class="p">(</span><span class="s1">'init.lua'</span><span class="p">).</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bundle_init</span><span class="w"> </span><span class="ss">:name</span><span class="w">&#x000A;&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_all</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">not_nil</span><span class="w"> </span><span class="n">bundles</span><span class="p">.</span><span class="n">foo</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">not_nil</span><span class="w"> </span><span class="n">bundles</span><span class="p">.</span><span class="n">bar</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="skips-any-hidden-entries">skips any hidden entries</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_tmpdir</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">dirs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="n">dir</span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">b_dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="s1">'.hidden'</span><span class="w">&#x000A;  </span><span class="n">b_dir</span><span class="o">\</span><span class="n">mkdir</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">b_dir</span><span class="o">\</span><span class="n">join</span><span class="p">(</span><span class="s1">'init.lua'</span><span class="p">).</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bundle_init</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'hidden'</span><span class="w">&#x000A;&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_all</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">[</span><span class="n">name</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">name</span><span class="p">,</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="nb">pairs</span><span class="w"> </span><span class="n">_G</span><span class="p">.</span><span class="n">bundles</span><span class="p">],</span><span class="w"> </span><span class="p">{}</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="load_by_name">load_by_name<span class="arg-list">(name)</span></h2>&#x000A;&#x000A;<h4 id="loads-the-bundle-with-the-specified-name,-if-not-already-loaded">loads the bundle with the specified name, if not already loaded</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_tmpdir</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">dirs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="n">dir</span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">b_dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="s1">'named'</span><span class="w">&#x000A;  </span><span class="n">b_dir</span><span class="o">\</span><span class="n">mkdir</span><span class="o">!</span><span class="w">&#x000A;  </span><span class="n">b_dir</span><span class="o">\</span><span class="n">join</span><span class="p">(</span><span class="s1">'init.lua'</span><span class="p">).</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bundle_init</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'named'</span><span class="w">&#x000A;&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_by_name</span><span class="w"> </span><span class="s1">'named'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">not_nil</span><span class="w"> </span><span class="n">_G</span><span class="p">.</span><span class="n">bundles</span><span class="p">.</span><span class="n">named</span><span class="w">&#x000A;&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'loaded'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_by_name</span><span class="w"> </span><span class="s1">'named'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="raises-an-error-if-the-bundle-could-not-be-found">raises an error if the bundle could not be found</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'not found'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_by_name</span><span class="w"> </span><span class="s1">'oh_bundle_where_art_thouh'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="unload">unload<span class="arg-list">(name)</span></h2>&#x000A;&#x000A;<h4 id="raises-an-error-if-no-bundle-with-the-given-name-exists">raises an error if no bundle with the given name exists</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'not found'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">unload</span><span class="w"> </span><span class="s1">'serenity'</span></code></pre>&#x000A;&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(for an existing bundle)</span></h3>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">mod</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'bunny'</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="calls-the-bundle-unload-function-and-removes-the-bundle-from-_g.bundles">calls the bundle unload function and removes the bundle from _G.bundles</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_bundle_dir</span><span class="w"> </span><span class="s1">'bunny'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">dir</span><span class="o">\</span><span class="n">join</span><span class="p">(</span><span class="s1">'init.lua'</span><span class="p">).</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bundle_init</span><span class="w"> </span><span class="n">mod</span><span class="p">,</span><span class="w"> </span><span class="ss">unload:</span><span class="w"> </span><span class="s1">'function() _G.bunny_bundle_unload = true end'</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_from_dir</span><span class="w"> </span><span class="n">dir</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">unload</span><span class="w"> </span><span class="s1">'bunny'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_true</span><span class="w"> </span><span class="n">_G</span><span class="p">.</span><span class="n">bunny_bundle_unload</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">bundles</span><span class="p">.</span><span class="n">bunny</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="returns-early-with-an-error-if-the-unload-function-raises-an-error">returns early with an error if the unload function raises an error</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_bundle_dir</span><span class="w"> </span><span class="s1">'bad_seed'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">dir</span><span class="o">\</span><span class="n">join</span><span class="p">(</span><span class="s1">'init.lua'</span><span class="p">).</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bundle_init</span><span class="w"> </span><span class="n">mod</span><span class="p">,</span><span class="w"> </span><span class="ss">unload:</span><span class="w"> </span><span class="s1">'function() error("barf!") end'</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_from_dir</span><span class="w"> </span><span class="n">dir</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">raises</span><span class="w"> </span><span class="s1">'barf!'</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">unload</span><span class="w"> </span><span class="s1">'bad_seed'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_not_nil</span><span class="w"> </span><span class="n">bundles</span><span class="p">.</span><span class="n">bad_seed</span></code></pre>&#x000A;&#x000A;&#x000A;<h4 id="transforms-the-given-name-to-match-the-module-name">transforms the given name to match the module name</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_bundle_dir</span><span class="w"> </span><span class="s1">'dash-love'</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">dir</span><span class="o">\</span><span class="n">join</span><span class="p">(</span><span class="s1">'init.lua'</span><span class="p">).</span><span class="n">contents</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">bundle_init</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'dash-love'</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">load_from_dir</span><span class="w"> </span><span class="n">dir</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">no_error</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">unload</span><span class="w"> </span><span class="s1">'dash-love'</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="from_file">from_file<span class="arg-list">(file)</span></h2>&#x000A;&#x000A;<h4 id="returns-the-adjusted-name-of-the-containing-bundle-if-any">returns the adjusted name of the containing bundle if any</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><code><span class="n">with_tmpdir</span><span class="w"> </span><span class="p">(</span><span class="n">dir</span><span class="p">)</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">bundle</span><span class="p">.</span><span class="n">dirs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="n">dir</span><span class="p">}</span><span class="w">&#x000A;  </span><span class="n">b_dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dir</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="s1">'my-bundle'</span><span class="w">&#x000A;  </span><span class="n">init</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">b_dir</span><span class="o">\</span><span class="n">join</span><span class="p">(</span><span class="s1">'init.lua'</span><span class="p">)</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'my_bundle'</span><span class="p">,</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">init</span><span class="p">)</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">from_file</span><span class="p">(</span><span class="nc">File</span><span class="p">(</span><span class="s1">'/bin/ls'</span><span class="p">))</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">bundle</span><span class="p">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">dir</span><span class="o">\</span><span class="n">join</span><span class="p">(</span><span class="s1">'directly_under_root'</span><span class="p">))</span></code></pre>&#x000A;&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2015
            <a class='alert-link' href='https://github.com/nilnor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
